<h1>Create Department</h1>
<table width="100%" class="table">
  <tr>
    <td width="30%">Department Name</td>
    <td width="70%">Description</td>
    <td width="70%">&nbsp;</td>
  </tr>
  <tr valign="top">
    <td>
      <input type="text" class="input-big" placeholder="Department Name" id="name" />
  </td>
    <td><textarea name="textarea" class="input-big" placeholder="Department description" id="desc" ></textarea></td>   
    <td><input type="submit" value="Create Department" id="create_department" class="btn btn-success" /></td>
  </tr>

</table>
<hr />


<table width="100%" id="example" class="table">
  <thead>
  <tr>
    <th>Department Id</th>
    <th>Name</td>
    <th>Description</th>
    </tr>
  </thead>
  <?php foreach($departments as $department) {?>
  <tr>
    <td><?= $department->id?></td>
    <td><?= $department->name?></td>
    <td><?= $department->description?></td>
  </tr>
  <?php }?>
</table>
<script type="text/javascript">
$('#create_department').click(function () {	
	if(!$('#name').val())
	{
	alert('Department Name Field is Required');	
	$('#name').focus()
	}
	else if(!$('#desc').val())
	{
		alert('Description Field is Required');
		$('#desc').focus()
	}
	else {
	var user_name = $('#name').val();
	var desc = $('#desc').val();	
	$.post('<?= site_url('founder/user/create_department');?>',{name : user_name  , desc : desc }, function(data) {	
	 $('#name,#desc').val("");
	  location.reload(); 
	 });
	}	
})	
</script>